# Locate libusb library
# This module defines
# LIBUSB_FOUND, if false, do not try to link to libusb
# LIBUSB_INCLUDE_DIRS, where to find the headers
# LIBUSB_LIBRARIES, the libraries to link against

# 在系统中查找 libusb 库及其相关头文件的路径。
# 它使用了 CMake 的 `find_path` 命令来搜索名为 `libusb.h` 的头文件，
# 然后尝试在指定的路径下查找该头文件。如果找到了，
# 则会将路径存储在变量 `LIBUSB_INCLUDE_DIR` 中。
# 在这个例子中，搜索的路径包括 `/usr/include` 和 `/usr/local/include`，
# 并且在 `/usr/include/libusb-1.0` 和 `/usr/local/include/libusb-1.0` 
# 目录中寻找 `libusb.h` 头文件。

# x86
# find_path(LIBUSB_INCLUDE_DIR
#     NAMES
#     libusb.h
#     PATH_SUFFIXES
#     libusb-1.0   # PATHS目录中的libusb-1.0子目录
#     PATHS
#     /usr/include
#     /usr/local/include
# )

# find_library(LIBUSB_LIBRARY
#     NAMES
#     usb-1.0
#     PATH_SUFFIXES
#     x86_64-linux-gnu # PATHS目录中的x86_64-linux-gnu子目录
#     PATHS
#     /usr/lib
#     /usr/local/lib
#     /lib
# )

# arm
find_path(LIBUSB_INCLUDE_DIR
    NAMES
    libusb-1.0/libusb.h
    PATHS
    /home/mat/workspace/C/usb/libusb-1.0.23/tmp/include
)

find_library(LIBUSB_LIBRARY
    NAMES
    usb-1.0
    PATHS
    /home/mat/workspace/C/usb/libusb-1.0.23/tmp/lib
)

if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARY)
    set(LIBUSB_FOUND TRUE)
else()
    set(LIBUSB_FOUND FALSE)
endif()

if(LIBUSB_FOUND)
    if(NOT LibUsb_FIND_QUIETLY)
        message(STATUS "Found libusb: ${LIBUSB_LIBRARY}")
    endif()
else()
    if(LibUsb_FIND_REQUIRED)
        message(FATAL_ERROR "libusb not found")
    endif()
endif()

set(LIBUSB_INCLUDE_DIRS ${LIBUSB_INCLUDE_DIR})
set(LIBUSB_LIBRARIES ${LIBUSB_LIBRARY})
